/*
 * HomeShopListItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.data.bean.Shop;
import com.yidiandao.business.ui.goodsdetail.GoodsDetailActivity;
import com.yidiandao.business.ui.shopdetail.ShopDetailActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.ShopHolder;
import com.yidiandao.business.utils.UmengUtils;

import java.util.List;

/** 首页-商店-ListItem */
public class ShopListItem extends DisplayListItem<ShopHolder, Shop>
        implements View.OnClickListener {

    private Activity mActivity;

    public ShopListItem(Shop s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, ShopHolder holder) {
        mActivity = (Activity) context;

        holder.refreshUI(data);

        // 进入店铺详情
        holder.mTvGoToShop.setOnClickListener(this);

        holder.mIvImage1.setOnClickListener(this);
        holder.mIvImage2.setOnClickListener(this);
        holder.mIvImage3.setOnClickListener(this);

        holder.mTvPrice1.setOnClickListener(this);
        holder.mTvPrice2.setOnClickListener(this);
        holder.mTvPrice3.setOnClickListener(this);
    }

    @Override
    public String getDisplayItemTag() {
        return ShopListItem.class.getSimpleName();
    }

    @Override
    public Class<ShopHolder> getViewHolderClazz() {
        return ShopHolder.class;
    }

    @Override
    public void onClick(View v) {

        List<Goods> goodsList = data.getGoodsInfo();

        try {
            switch (v.getId()) {
                case R.id.tv_go_to_shop:
                    // 进入店铺详情
                    UmengUtils.onEvent(mActivity, R.string.umeng_home_to_show_detail);
                    ShopDetailActivity.actionStart(mActivity, data.getSupplierId());
                    break;
                case R.id.iv_image_1:
                    UmengUtils.onEvent(
                            mActivity, R.string.umeng_home_click_show_to_goods_detail);
                    Goods goods1 = goodsList.get(0);
                    GoodsDetailActivity.actionStart(mActivity, goods1.getGoodsId());
                    break;
                case R.id.iv_image_2:
                    UmengUtils.onEvent(
                            mActivity, R.string.umeng_home_click_show_to_goods_detail);
                    Goods goods2 = goodsList.get(1);
                    GoodsDetailActivity.actionStart(mActivity, goods2.getGoodsId());
                    break;
                case R.id.iv_image_3:
                    UmengUtils.onEvent(
                            mActivity, R.string.umeng_home_click_show_to_goods_detail);
                    Goods goods3 = goodsList.get(2);
                    GoodsDetailActivity.actionStart(mActivity, goods3.getGoodsId());
                    break;
//                case R.id.tv_price_1:
//                case R.id.tv_price_2:
//                case R.id.tv_price_3:
//                    if (!PriceUtils.isLogin()) {
//                        LoginActivity.actionStart(mActivity);
//                    }
//                    break;
            }
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();
        }
    }
}
